package S02lianbiao;

public class T0203 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public static void main(String[] args) {

    }
    public static ListNode removeElements(ListNode head, int val) {
        if(head==null){
            return null;
        }
        head.next=removeElements(head.next,val);
        if(head.val==val){
            return head.next;
        }else {
            return head;
        }


    }
    public static ListNode removeElements2(ListNode head, int val) {
        ListNode kong=new ListNode(0);
        kong.next=head;
        ListNode a=kong;
        while (a.next!=null){
            if(a.next.val==val){
                a.next=a.next.next;
            }else {
                a=a.next;
            }


        }
        return kong.next;


    }

}



